package com.dj.ms.resolver;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <br>
 * <p>web exception handler</p>
 *
 * <br>
 *
 * @author ZJG
 * @version 1.0
 * @date 2021/8/13 下午1:48
 */
@Slf4j
@Component
public class WebExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {
        log.warn("WebExceptionResolver ex::{}, StackTrace::{}", e.getMessage(), e.getStackTrace().toString());
        return new ModelAndView("redirect:/ex/process?msg=" + e.getMessage());
    }
}
